package com.whalehearing.tingyou.web.controller.hearing;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.whalehearing.tingyou.common.annotation.DataSource;
import com.whalehearing.tingyou.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.enums.BusinessType;
import com.whalehearing.tingyou.domain.HearingImgValue;
import com.whalehearing.tingyou.service.IHearingImgValueService;
import com.whalehearing.tingyou.common.utils.poi.ExcelUtil;
import com.whalehearing.tingyou.common.core.page.TableDataInfo;

/**
 * 听力值Controller
 *
 * @author zengjun-qxm
 * @date 2024-09-18
 */
@Api(tags="听力值管理")
@RestController
@DataSource(DataSourceType.SLAVE)
@RequestMapping("system/hearing/value")
public class HearingImgValueController extends BaseController
{
    @Autowired
    private IHearingImgValueService hearingImgValueService;

    /**
     * 查询听力值列表
     */
    @ApiOperation("查询听力值列表")
    @PreAuthorize("@ss.hasPermi('hearing:value:list')")
    @GetMapping("/list")
    public TableDataInfo list(HearingImgValue hearingImgValue)
    {
        startPage();
        List<HearingImgValue> list = hearingImgValueService.selectHearingImgValueList(hearingImgValue);
        return getDataTable(list);
    }

    /**
     * 导出听力值列表
     */
    @ApiOperation("导出听力值列表")
    @PreAuthorize("@ss.hasPermi('hearing:value:export')")
    @Log(title = "听力值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HearingImgValue hearingImgValue)
    {
        List<HearingImgValue> list = hearingImgValueService.selectHearingImgValueList(hearingImgValue);
        ExcelUtil<HearingImgValue> util = new ExcelUtil<HearingImgValue>(HearingImgValue.class);
        util.exportExcel(response, list, "听力值数据");
    }

    /**
     * 获取听力值详细信息
     */
    @ApiOperation("获取听力值详细信息")
    @PreAuthorize("@ss.hasPermi('hearing:value:query')")
    @GetMapping(value = "/{hearingImgValueId}")
    public AjaxResult getInfo(@PathVariable("hearingImgValueId") Long hearingImgValueId)
    {
        return success(hearingImgValueService.getById(hearingImgValueId));
    }

    /**
     * 新增听力值
     */
    @ApiOperation("新增听力值")
    @PreAuthorize("@ss.hasPermi('hearing:value:add')")
    @Log(title = "听力值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HearingImgValue hearingImgValue)
    {
        return toAjax(hearingImgValueService.save(hearingImgValue));
    }

    /**
     * 修改听力值
     */
    @ApiOperation("修改听力值")
    @PreAuthorize("@ss.hasPermi('hearing:value:edit')")
    @Log(title = "听力值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HearingImgValue hearingImgValue)
    {
        return toAjax(hearingImgValueService.updateById(hearingImgValue));
    }

    /**
     * 删除听力值
     */
    @ApiOperation("删除听力值")
    @PreAuthorize("@ss.hasPermi('hearing:value:remove')")
    @Log(title = "听力值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hearingImgValueIds}")
    public AjaxResult remove(@PathVariable Long[] hearingImgValueIds)
    {
        return toAjax(hearingImgValueService.removeByIds(Arrays.asList(hearingImgValueIds)));
    }
}
